<?php
namespace core\http;

class Response extends HttpMessage implements \Psr\Http\Message\ResponseInterface
{
    protected $headers = []; // 要发送的请求头
    protected $content = ''; // 要发送的内容
    protected $code = 200; // 发送状态码

    public function getStatusCode()
    {
        return $this->code;
    }

    public function withStatus($code, $reasonPhrase = '')
    {
         $this->code;
        return $this;
    }

    public function getReasonPhrase()
    {
        // TODO: Implement getReasonPhrase() method.
    }

    public function sendContent() // 发送内容
    {
        echo $this->content;
    }

    public function sendHeaders() // 发送请求头
    {
        foreach ($this->headers as $key => $header)
        {
            header($key.': '.$header);
        }

    }

    public function send() // 发送
    {
        $this->sendHeaders();
        $this->sendContent();
        return $this;
    }

    public function setContent($content) // 设置内容
    {

        if( is_array($content))
        {
            $content = json_encode($content);
        }
        $this->content = $content;
        return $this;
    }
    public function setCode(int $code) // 设置响应码
    {
        $this->code = $code;
        return $this;
    }
    
    public function getContent() // 获取内容
    {
        return $this->content;
    }

}